package com.second.app.thread.change;

/**
 * @Author soul gao
 * @Date 2021/1/24 16:02
 * 努力学习 天天进步
 */
public class Subtract {

    private String lock;

    public Subtract(String lock) {
        this.lock = lock;
    }

    public void subtract() {
        synchronized (lock) {
            try {
                while (ValueObject.getList().size() == 0) {
                    System.out.println(Thread.currentThread().getName() + "开始等待:" + System.currentTimeMillis());
                    lock.wait();
                    System.out.println(Thread.currentThread().getName() + "结束等待:" + System.currentTimeMillis());
                }
                ValueObject.getList().remove(0);
                System.out.println("list size:" + ValueObject.getList().size());
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
